package com.beeway.blackgoose.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.beeway.blackgoose.R;
import com.beeway.blackgoose.adapter.StoreListAdapter;
import com.beeway.blackgoose.bean.ListMessage;
import com.beeway.blackgoose.bean.MyStore;
import com.beeway.blackgoose.constants.Config;
import com.beeway.blackgoose.utils.Utils;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class StoreShopFragment extends Fragment implements PullToRefreshBase.OnRefreshListener2<ListView> {
    private View shopView;
    @ViewInject(R.id.store_show_ptrlv)
    private PullToRefreshListView shopPtrlv;
    private List<MyStore> shopData;
    private StoreListAdapter shopAdapter;

    private HttpHandler<String> handler;
    private HttpUtils utils;
    public StoreShopFragment() {
    }

    public static StoreShopFragment getInstance() {
        StoreShopFragment shop = new StoreShopFragment();
        return shop;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        shopView = inflater.inflate(R.layout.fragment_sotre_shop, container, false);
        ViewUtils.inject(this, shopView);
        initView();
        initDate();
        return shopView;
    }

    private void initView() {
        shopPtrlv.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        shopData = new ArrayList<>();
        shopAdapter = new StoreListAdapter(getActivity(), shopData, Utils.getBitmapUtils(getActivity()));
        shopPtrlv.setAdapter(shopAdapter);
        shopPtrlv.setOnRefreshListener(this);
    }

    private void initDate() {
        utils = new HttpUtils();
        handler = utils.send(HttpRequest.HttpMethod.POST, Config.MYSTORE_URL, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });

    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

    }
}
